<?php
/**
 * Created by PhpStorm.
 * User: JinLei
 * Date: 2018/1/29
 * Time: 15:31
 */
namespace Home\Model;
use Think\Model;
class SurveyinfoModel extends Model{
    /**
     * 获取问卷信息
     * @param int $id
     * @return mixed
     */
    public function getInfo($id) {
        $where['status'] = 1;
        $where['surveyid'] = $id;
        $info = $this->where($where)->find();
        if(!$info) return -5;

        $question = new QuestionModel();
        $quest = $question->getQuest($id);

        $options = new OptionsModel();
        $quests['sid'] = $info['surveyid']; //问卷id
        $quests['name'] = $info['surveyname']; //问卷名字
        $quests['desc'] = $info['surveydesc'];  //问卷描述
        foreach ($quest as $k =>$v){
            $id = $v['questionid'];
            $opt[$id]['question'] = $v['questioncontent'];
            $opt[$id]['questionno'] = $v['questionno'];
            $opt[$id]['questno'] = $v['questionno']+1;//页面显示题目号
            $opt[$id]['isrequired'] = $v['isrequired'];
            $opt[$id]['description'] = $v['description'];
            $opt[$id]['questiontype'] = $v['questiontype'];
            $opt[$id]['questionid'] = $v['questionid'];
            $opt[$id]['options'] = $options->getOptions($v['questionid']);
        }
        $quests['quest'] = $opt;
        return $quests;
    }

    /**
     * @param $id
     * @return bool
     * 增加访问记录
     */
    public function updatePageview($id){
        $id = I('post.id');
        if($id){
            $where['surveyid'] = $id;
            return $this->where($where)->setInc("pageview");
        }
    }

}